from selenium import webdriver
from time import sleep
# 实现无可视化界面
from selenium.webdriver.chrome.options import Options
# 实现回避检测
from selenium.webdriver import ChromeOptions
# 创建一个参数对象，用来控制chrome以无界面模式打开
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')

# 反检测，防止门户网站识别出selenium,是selenium无效化
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])

bro = webdriver.Chrome(executable_path='./chromedriver', chrome_options=chrome_options, options=option)

# 无可视化界面（无头浏览器）phantomJs
bro.get('https://www.baidu.com')



print(bro.page_source)
sleep(2)
bro.quit()